﻿//  --------------------------------
//  Copyright (c) PK Logix LLC. All rights reserved.
//  This source code is made available under the terms of the GNU General Public License version 2 (GPLv2)
//  http://www.codeplex.com/mvcclubsite/license
//  ---------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MVCClubSite.IDAL;
using MVCClubSite.Model;

namespace MVCClubSite.BLL
{
    /// <summary>
    /// This is the business component to manage links
    /// </summary>
    public class LinksService
    {
        ILinks _links;

        /// <summary>
        /// Default constructor that will use the DAL set in the web config
        /// </summary>
        public LinksService()
        {
            _links = MVCClubSite.DALFactory.DataAccess.CreateLinks();
        }

        /// <summary>
        /// Constructor for testing with a different DAL
        /// </summary>
        /// <param name="announcements">DAL for the announcement service to use</param>
        public LinksService(ILinks links)
        {
            _links = links;
            if (_links == null)
                throw new InvalidOperationException("Links DAL cannot be null.");
        }

        /// <summary>
        /// Method to get links
        /// </summary>
        /// <returns>List of Links</returns>
        public List<Link> GetLinks()
        {
            return (from l in _links.GetLinks()
                    orderby l.Sequence ascending
                    select l).ToList();

        }

        /// <summary>
        /// Method to get a link by ID
        /// </summary>
        /// <param name="id">ID of the link</param>
        /// <returns>Link business entity</returns>
        public Link GetLinkByID(int id)
        {
            return _links.GetLinkByID(id);
        }

        /// <summary>
        /// Method to get the ID of the link image
        /// </summary>
        /// <param name="id">ID of the link</param>
        /// <returns>Btye array of the link image</returns>
        public byte[] GetLinkImage(int id)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Method to insert or update a link
        /// </summary>
        /// <param name="link">Link business entity</param>
        public void Save(Link link)
        {
            _links.Save(link);  
        }

        /// <summary>
        /// Method to delete a link
        /// </summary>
        /// <param name="id">ID of the link to delete</param>
        public void Delete(int id)
        {
            _links.Delete(id);
        }

    }
}
